<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<table   id="buy"        width="300"     border="1" cellspacing="0" cellpadding="0">
			<thead>
				<th><input type="checkbox" name="all" id="all" value="quanxuan" />全选</th>
				<th>Header</th>
				<th>Header</th>
				<th>Header</th>
				<th>Header</th>
				<th>操作</th>
			</thead>
			<tbody>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>产品名称</td>
					<td>99</td>
					<td><input size="4" type="text"/></td>
					<td>99</td>
					<td><input type="button" name="" id="" value="删除" onclick="del(this.parentNode.parentNode)"/></td>
					
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>产品名称</td>
					<td>66</td>
					<td><input size="4" type="text"/></td>
					<td>66</td>
					<td><input type="button" name="" id="" value="删除" onclick="del(this.parentNode.parentNode)"/></td>
					
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
						<td>产品名称</td>
					<td>33</td>
					<td><input size="4" type="text"/></td>
					<td>33</td>
					<td><input type="button" name="" id="" value="删除" onclick="del(this.parentNode.parentNode)"/></td>
				</tr>
				<tfoot>
					<td></td>
					<td></td>
					<td>总计</td>
					<td colspan="3" id="foot">0</td>
					
				</tfoot>
			</tbody>
		</table>
		<script type="text/javascript">
			var   buy=document.getElementById("buy");
			var   inputs=buy.getElementsByTagName("input")
			for (var i = 0; i < inputs.length; i++) {
				inputs[i].onchange=function(){
				var tr=this.parentNode.parentNode;
				//console.log(tr);
				var dj=tr.children[2].innerHTML;
				 var num=this.value;
				 var  sum=num*dj;
				 tr.children[4].innerHTML=sum;
				footsum();
				}
				}
			function del(tr) {
				if(confirm("是否确认删除?")) {
					buy.children[1].removeChild(tr);
					footsum();
				}
			}

			
		function footsum(){
			sum=0;
			   trs=buy.children[1].children;
			   for (var i = 0; i < trs.length; i++) {
			   	if(trs[i].firstElementChild.firstElementChild.checked)
			  {
			  	 sum+=parseFloat(trs[i].children[4].innerHTML);
			  	  console.log(trs[i].children[4].innerHTML);
			  }
			   }
			  document.getElementById("foot").innerHTML=sum;
			
		}
				
			
				
				
				
			
		</script>
	</body>

</html>